<?php
class User extends AppModel {
var $name = "User";

    
    //--------- Compare Pass
    function ComparePass(){
        if($this->data['User']['pass']!=$this->data['User']['re_pass']){
            return FALSE;
        }
        else{
            return TRUE;
        }
    }
    
    //-------- Check Useranme
    function checkUsername(){
        if(isset($this->data[$this->name]['id'])){
            $where = array(
                            "id !=" => $this->data[$this->name]['id'],
                            "username" => $this->data[$this->name]['username'],
                            ); 
                 
        }
        else{
            $where = array(
                            "username" => $this->data[$this->name]['username'],
                            );  
        } 
        $this->find($where);
        $count = $this->getNumRows();
        if($count!=0){
            return false;
        }
        else{
            return true;
        }
    }
    
    //--- HashPassword
    function hashPassword($data){
        if(isset($this->data['User']['pass'])){
            $this->data['User']['password'] = Security::hash($this->data['User']['pass'],NULL,TRUE);
            return $data;
        }
        return $data;
    }
    //----- beforeSave
    function beforeSave(){
        $this->hashPassword(NULL,TRUE);
        return TRUE;
    } 
    
      
}
?>